//package com.vf.admin.common.db.SqlUitls;
//
//import java.beans.IntrospectionException;
//import java.lang.reflect.Field;
//import java.lang.reflect.InvocationTargetException;
//import java.sql.PreparedStatement;
//import java.sql.SQLException;
//import java.util.HashMap;
//import java.util.Map;
//
//import com.vf.admin.common.db.utils.PojoBySql;
//import org.apache.commons.beanutils.PropertyUtilsBean;
//import org.apache.log4j.Logger;
//
//import com.zhidong.core.aop.Aspect.DbUtils;
//import com.zhidong.core.orm.annotation.Column;
//import com.zhidong.core.orm.annotation.Table;
//import com.zhidong.core.orm.entity.PojoBySql;
//
///**
// * 进行delete语句的执行
// *
// */
//public class DeleteSql {
//	private Logger log = Logger.getLogger(DeleteSql.class);
//	public static DeleteSql getInstance(){
//		return new DeleteSql();
//	}
//
//	/**
//	 * 对象进行删除操作
//	 * @param obj
//	 * @throws SQLException
//	 * @throws IllegalAccessException
//	 * @throws InvocationTargetException
//	 * @throws NoSuchMethodException
//	 * @throws InstantiationException
//	 */
//	public void update(Object obj) throws SQLException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException{
//		PojoBySql pojobysql = PojoBySql.class.newInstance();
//		try {
//			PojoConverSql.getInstance().pojoBySql(obj, pojobysql);
//		} catch (IntrospectionException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}   //获取属性和属性对应的数据
//		                              //获取属性对应的表字段
//
//		//拼接sql
//		StringBuffer udpateNameBuffer = new StringBuffer();
//		StringBuffer udpateDataBuffer = new StringBuffer();
//
//		StringBuffer whereNameBuffer = new StringBuffer();
//		StringBuffer whereDataBuffer = new StringBuffer();
//
//
//		if(pojobysql.getColumnDateMap()!=null && pojobysql.getColumnDateMap().size()>=1){
//			for(Map.Entry<String, Object> entry: pojobysql.getColumnDateMap().entrySet()) {
//				if(pojobysql.getIndexName().equals(entry.getKey())){
//					continue;
//				}
//				udpateNameBuffer.append(entry.getKey()+" = ?  ,");
//			}
//			udpateNameBuffer = udpateNameBuffer.replace(udpateNameBuffer.length()-1, udpateNameBuffer.length(),"");
//		}
//		if(pojobysql.getIndexName()!=null && !pojobysql.getIndexName().equals("")){
//			whereNameBuffer.append(" where ");
//			whereNameBuffer.append(pojobysql.getIndexName()+" = ?  ,");
//			whereNameBuffer = whereNameBuffer.replace(whereNameBuffer.length()-1, whereNameBuffer.length(),"");
//		}
//		String sql = "update  "+pojobysql.getTableName() + " set "+udpateNameBuffer + whereNameBuffer;
//		log.info("保存sql:" + sql);
//
//
//		PreparedStatement ps = DbUtils.getConnection().prepareStatement(sql);
//		int j = 1;
//		if(pojobysql.getColumnDateMap()!=null && pojobysql.getColumnDateMap().size()>=1){
//			for(Map.Entry<String, Object> entry: pojobysql.getColumnDateMap().entrySet()) {
//				if(pojobysql.getIndexName().equals(entry.getKey())){
//					continue;
//				}
//				Object valueobj = pojobysql.getColumnDateMap().get(entry.getKey());
//				ps.setString(j, valueobj.toString());
//				j++;
//			}
//		}
//		if(pojobysql.getIndexName()!=null && !pojobysql.getIndexName().equals("")){
//				ps.setString(j, pojobysql.getColumnDateMap().get(pojobysql.getIndexName()).toString());
//		}
//
//		ps.execute();
//
//	}
//
//	/**
//	 * 对象进行删除操作
//	 * @param obj
//	 * @throws SQLException
//	 * @throws IllegalAccessException
//	 * @throws InvocationTargetException
//	 * @throws NoSuchMethodException
//	 * @throws InstantiationException
//	 */
//	public void del(Object obj,HashMap<String , Object> whereMap) throws SQLException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException{
//		PojoBySql pojobysql = PojoBySql.class.newInstance();
//		try {
//			PojoConverSql.getInstance().pojoBySql(obj, pojobysql);
//		} catch (IntrospectionException e) {
//			e.printStackTrace();
//		}   //获取属性和属性对应的数据
//		 //获取属性对应的表字段
//		//拼接sql
//		StringBuffer whereNameBuffer = new StringBuffer();
//
//		if(whereMap!=null && whereMap.size()>=1){
//			whereNameBuffer.append(" where ");
//			for(Map.Entry<String , Object> entry: whereMap.entrySet()) {
//				whereNameBuffer.append(entry.getKey()+"  ?, ");
//			}
//			whereNameBuffer = whereNameBuffer.delete(whereNameBuffer.lastIndexOf(","), whereNameBuffer.length());
//		}else{
//			whereNameBuffer.append(" where "+pojobysql.getIndexName()+" = ?");
//		}
//		String sql = "delete from  "+pojobysql.getTableName() + whereNameBuffer;
//		log.info("sql:" + sql);
//
//
//		PreparedStatement ps = DbUtils.getConnection().prepareStatement(sql);
//		int j = 1;
//		if(whereMap!=null && whereMap.size()>=1){
//			for(Map.Entry<String, Object> entry: whereMap.entrySet()) {
//				Object valueobj = whereMap.get(entry.getKey());
//				ps.setObject(j, valueobj);
//				j++;
//			}
//		}else{
//			if(pojobysql.getIndexName()!=null && !pojobysql.getIndexName().equals("")){
//				ps.setString(j, pojobysql.getColumnDateMap().get(pojobysql.getIndexName()).toString());
//			}
//		}
//		if((whereMap==null || whereMap.size()<=0) && (pojobysql.getIndexName()==null || pojobysql.getIndexName().trim().equals("")) ){
//			return ;
//		}else{
//			ps.execute();
//		}
//	}
//
//
//
//
//	/**
//	 * 对象进行更新操作
//	 * @param obj
//	 * @throws SQLException
//	 * @throws IllegalAccessException
//	 * @throws InvocationTargetException
//	 * @throws NoSuchMethodException
//	 * @throws InstantiationException
//	 */
//	public void update(Object obj,HashMap<String , Object> whereMap) throws SQLException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException{
//		PojoBySql pojobysql = PojoBySql.class.newInstance();
//		try {
//			PojoConverSql.getInstance().pojoBySql(obj, pojobysql);
//		} catch (IntrospectionException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}   //获取属性和属性对应的数据
//		                              //获取属性对应的表字段
//
//		//拼接sql
//		StringBuffer udpateNameBuffer = new StringBuffer();
//		StringBuffer udpateDataBuffer = new StringBuffer();
//
//		StringBuffer whereNameBuffer = new StringBuffer();
//		StringBuffer whereDataBuffer = new StringBuffer();
//
//
//		if(pojobysql.getColumnDateMap()!=null && pojobysql.getColumnDateMap().size()>=1){
//			for(Map.Entry<String, Object> entry: pojobysql.getColumnDateMap().entrySet()) {
//				udpateNameBuffer.append(entry.getKey()+" = ? , ");
//			}
//			udpateNameBuffer = udpateNameBuffer.replace(udpateNameBuffer.length()-1, udpateNameBuffer.length(),"");
//		}
//
//		if(whereMap!=null && whereMap.size()>=1){
//			whereNameBuffer.append(" where ");
//			for(Map.Entry<String , Object> entry: whereMap.entrySet()) {
//				whereNameBuffer.append(entry.getKey()+" = ?, ");
//			}
//			whereNameBuffer = whereNameBuffer.replace(whereNameBuffer.length()-1, whereNameBuffer.length(),"");
//		}
//		String sql = "update  "+pojobysql.getTableName() + " set "+udpateNameBuffer+ " where " + whereNameBuffer + ")";
//		log.info("保存sql:" + sql);
//
//
//		PreparedStatement ps = DbUtils.getConnection().prepareStatement(sql);
//		int j = 1;
//		if(pojobysql.getColumnDateMap()!=null && pojobysql.getColumnDateMap().size()>=1){
//			for(Map.Entry<String, Object> entry: pojobysql.getColumnDateMap().entrySet()) {
//				Object valueobj = pojobysql.getColumnDateMap().get(entry.getKey());
//				ps.setObject(j, valueobj);
//				j++;
//			}
//		}
//		if(whereMap!=null && whereMap.size()>=1){
//			for(Map.Entry<String , Object> entry: whereMap.entrySet()) {
//				Object valueobj = whereMap.get(entry.getKey());
//				ps.setObject(j, valueobj);
//				j++;
//			}
//		}
//		ps.execute();
//
//	}
////	/**
////	 * 把pojo实体对象转换成插入的sql
////	 *
////	 * @throws NoSuchMethodException
////	 * @throws InvocationTargetException
////	 * @throws IllegalAccessException
////	 * @throws SQLException
////	 * @throws IntrospectionException
////	 */
////	private void pojoBySql(Object obj,PojoBySql pojobysql) throws IllegalAccessException,
////			InvocationTargetException, NoSuchMethodException, SQLException, IntrospectionException {
////		Class clas = obj.getClass();
////		String clasName = "";
////		try{
////		   clasName = clas.getName();
////		}catch(Exception e){
////			System.out.println(e);
////		}
////		String tableName = "";
////		HashMap<String, String> objTableMap = new HashMap<String, String>();
////		HashMap<String, Object> columnDateMap = new HashMap<String, Object>();
////
////		//类名称
////		if (clasName.indexOf(".") >= 0) {
////			clasName = clasName.substring(clasName.lastIndexOf(".") + 1,clasName.length());
////			tableName = clasName;    //表名称做注解则默:类名为表名称
////		}
////		//类名称对应的表名称
////		if(clas.isAnnotationPresent(Table.class)){
////			Table table = (Table) clas.getAnnotation(Table.class);    //该class存在Table类型的注解，获取指定的表名
////			tableName = table.name();
////
////		}
////
////		Field[] fieldArray = clas.getDeclaredFields();
////
////		for (Field  field : fieldArray) {
////			String name = field.getName(); //成员变量名
////			Class type = field.getType(); //成员变量类型
////			System.out.println("name:"+name+",type:"+type);
////		}
////		System.out.println("---------------------------------");
////		for (Field  field : fieldArray) {
////			String name = field.getName(); //成员变量名
////			Class type = field.getType(); //成员变量类型
////			System.out.println("name:"+name+",type:"+type);
////			Object data = new PropertyUtilsBean().getNestedProperty(obj, name);    //成员变量值
////			String coluName = name;    //如果字段没有注解默认为成员变量名
////			int coluLength = 32;    //默认为32位长度
////			boolean index = false;    //默认不是主键
////			if(data!=null){
////				if(field.isAnnotationPresent(Column.class)){
////					Column column = field.getAnnotation(Column.class);//获取成员变量的注解实例
////					//获取元素值
////					coluName = column.name();    //变量对应的注解中的表字段名称
////					coluLength = column.length();
////					index = column.index();
////					if(index==true){
////						pojobysql.setIndexName(coluName);
////					}
////				}
////				columnDateMap.put(coluName,data);    //字段名称-值
////			}
////		}
////		pojobysql.setTableName(tableName);
////		pojobysql.setColumnDateMap(columnDateMap);
////	}
//}
